//
//  UIImage.swift
//  SwiftWeibo
//
//  Created by 苏强 on 16/12/5.
//  Copyright © 2016年 suqianghotel. All rights reserved.
//

import UIKit

import SDWebImage

extension UIImageView{
    
    
    func sq_setImage(with urlString:String?, placeholderImage:UIImage?, isCircle:Bool = false) -> () {
        
        guard
            
            let urlString = urlString,
            let url = URL(string:urlString)
            
        else {
            image = placeholderImage
            
            return
        }
        
        
    
        self.sd_setImage(with: url, placeholderImage: placeholderImage, options: [], progress: nil, completed:{(image,_,_,_) in
            
            let size = self.bounds.size
            
            let image = self.image
            
            if isCircle
            {
                self.image = image?.sq_circleImage(size: size, isCircle:isCircle)
                self.highlightedImage = image?.sq_circleImage(size: size, backgroundColor: UIColor(hex:0xEFEFEF), isCircle:isCircle)
            }
            else
            {
                self.image = image?.sq_image(size: size, backgroundColor: self.backgroundColor)
            }
            
           
    
        })
        
    }

}
    

